//
//  UFOInfoView.m
//  unrivalledForUniverse
//
//  Created by dllo on 16/1/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "UFOInfoView.h"
@interface UFOInfoView () <UITextFieldDelegate,UIApplicationDelegate>

@property (nonatomic, retain) UITapGestureRecognizer *tapImageGR;
@property (nonatomic, retain) UIView *dataV;
@property (nonatomic, retain) UIDatePicker *datePicker;
@property (nonatomic, retain) UIToolbar *toolB;
@property (nonatomic, retain) UIButton *button;

@end
@implementation UFOInfoView
- (void)dealloc
{
    [_nameTF release];
    [_genderTF release];
    [_areaTF release];
    [_numberTF release];
    [_nameL release];
    [_genderL release];
    [_areaL release];
    [_numberL release];
    [_headL release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews
{
    
    self.backgroundColor = [UIColor whiteColor];
    
    self.datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(150 *SCREENWIDTH / WIDTHSIXP, 330 * SCREENHEIGHT / HEIGHTSIXP, 180 * SCREENWIDTH / WIDTHSIXP, 150 * SCREENHEIGHT / HEIGHTSIXP)];
    self.datePicker.date = [NSDate date];
    self.datePicker.tag = 10001;
    self.datePicker.datePickerMode = UIDatePickerModeDate;
    [self.numberTF addSubview:self.datePicker];
    
    
    self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(155 *SCREENWIDTH /WIDTHSIXP, 60 *SCREENHEIGHT / HEIGHTSIXP , 60 *SCREENWIDTH / WIDTHSIXP, 60 * SCREENHEIGHT / HEIGHTSIXP )];
    self.imageV.image = [UIImage imageNamed:@"hero"];
    self.imageV.layer.cornerRadius = 30 *SCREENWIDTH / WIDTHSIXP;
    self.imageV.layer.masksToBounds = YES;
    self.imageV.userInteractionEnabled = YES;
    [self addSubview:self.imageV];
    [_imageV release];
    
    self.headL = [[UILabel alloc] initWithFrame:CGRectMake(155 *SCREENWIDTH / WIDTHSIXP, 110 *SCREENHEIGHT / HEIGHTSIXP, 60 *SCREENWIDTH /WIDTHSIXP, 60 *SCREENHEIGHT / HEIGHTSIXP)];
    self.headL.text = @"更换头像";
    self.headL.font = [UIFont systemFontOfSize:12.0];
    self.headL.textAlignment = NSTextAlignmentCenter;
    self.headL.textColor = [UIColor colorWithWhite:0.484 alpha:1.000];
    [self addSubview:self.headL];
    [self.headL release];
    
    self.nameL = [[UILabel alloc] initWithFrame:CGRectMake(50 *SCREENWIDTH / WIDTHSIXP, 180 *SCREENHEIGHT / HEIGHTSIXP, 80 *SCREENWIDTH /WIDTHSIXP, 30 *SCREENHEIGHT / HEIGHTSIXP)];
    self.nameL.text = @"昵称";
    self.nameL.textColor = [UIColor colorWithWhite:0.484 alpha:1.000];
    [self addSubview:self.nameL];
    [self.nameL release];
    
    self.nameTF = [[UITextField alloc] initWithFrame:CGRectMake(150 *SCREENWIDTH /WIDTHSIXP, 180 *SCREENHEIGHT / HEIGHTSIXP, 180 *SCREENWIDTH /WIDTHSIXP, 30*SCREENHEIGHT / HEIGHTSIXP)];
    self.nameTF.placeholder = @"昵称";
    self.nameTF.borderStyle = UITextBorderStyleRoundedRect;
    [self addSubview:self.nameTF];
    [self.nameTF release];
    
    self.genderL = [[UILabel alloc] initWithFrame:CGRectMake(50 *SCREENWIDTH / WIDTHSIXP, 230 *SCREENHEIGHT / HEIGHTSIXP, 80 *SCREENWIDTH / WIDTHSIXP, 30*SCREENHEIGHT / HEIGHTSIXP )];
    self.genderL.text = @"性别";
    self.genderL.textColor = [UIColor colorWithWhite:0.484 alpha:1.000];
    [self addSubview:self.genderL];
    [self.genderL release];
    
    self.genderTF = [[UITextField alloc] initWithFrame:CGRectMake(150 *SCREENWIDTH /WIDTHSIXP, 230 *SCREENHEIGHT / HEIGHTSIXP, 180 *SCREENWIDTH / HEIGHTSIXP, 30*SCREENHEIGHT / HEIGHTSIXP )];
    self.genderTF.placeholder = @"性别";
    self.genderTF.borderStyle = UITextBorderStyleRoundedRect;
    [self addSubview:self.genderTF];
    [self.genderTF release];
    
    self.areaL = [[UILabel alloc] initWithFrame:CGRectMake(50 *SCREENWIDTH / WIDTHSIXP, 280 *SCREENHEIGHT / HEIGHTSIXP, 80 *SCREENWIDTH / WIDTHSIXP, 30*SCREENHEIGHT / HEIGHTSIXP )];
    self.areaL.text = @"地区";
    self.areaL.textColor = [UIColor colorWithWhite:0.484 alpha:1.000];
    [self addSubview:self.areaL];
    [self.areaL release];
    
    self.areaTF = [[UITextField alloc] initWithFrame:CGRectMake(150 *SCREENWIDTH / WIDTHSIXP, 280 *SCREENHEIGHT / HEIGHTSIXP,180 *SCREENWIDTH / WIDTHSIXP, 30*SCREENHEIGHT / HEIGHTSIXP)];
    self.areaTF.placeholder = @"地区";
    self.areaTF.borderStyle = UITextBorderStyleRoundedRect;
    [self addSubview:self.areaTF];
    [self.areaTF release];
    
    self.numberL = [[UILabel alloc] initWithFrame:CGRectMake(50 *SCREENWIDTH / WIDTHSIXP, 330 *SCREENHEIGHT / HEIGHTSIXP, 80 *SCREENWIDTH /WIDTHSIXP, 30 *SCREENHEIGHT /HEIGHTSIXP)];
    self.numberL.text = @"出生日期";
    self.numberL.textColor = [UIColor colorWithWhite:0.484 alpha:1.000];
    [self addSubview:self.numberL];
    [self.numberL release];
    
    self.numberTF = [[UITextField alloc] initWithFrame:CGRectMake(150*SCREENWIDTH / WIDTHSIXP , 330 *SCREENHEIGHT / HEIGHTSIXP,180 *SCREENWIDTH / WIDTHSIXP, 30*SCREENHEIGHT / HEIGHTSIXP )];
    self.numberTF.placeholder = @"出生日期";
    self.numberTF.borderStyle = UITextBorderStyleRoundedRect;
    [self addSubview:self.numberTF];
    [self.numberTF release];
    
    self.numberTF.inputView = self.datePicker;
    
    
    
    
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self addGestureRecognizer:tapGR];
    [tapGR release];
    
    self.tapImageGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.imageV addGestureRecognizer:self.tapImageGR];
    [_tapImageGR release];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.numberTF.inputView = self.datePicker;
    self.numberTF.inputAccessoryView = self.toolB;
    return YES;
}

- (void)dateChanged:(id)sender {
    UIDatePicker *picker = (UIDatePicker *)sender;
    
    self.numberTF.text = [NSString stringWithFormat:@"%@", picker.date];
}

- (void)doneEditing:(id)sender {
    [self.numberTF resignFirstResponder];
}




- (void)tapAction:(UITapGestureRecognizer *)sender
{
    [self endEditing:YES];
    
    if (sender == self.tapImageGR) {
        [self.delegate headerImageHandle];
    }
    
}



- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    
    if (self.nameTF == textField) {
        [self.genderTF becomeFirstResponder];
    }
    if (self.genderTF == textField) {
        [self.areaTF becomeFirstResponder];
    }
    if (self.areaTF == textField) {
        [self.numberTF becomeFirstResponder];
    }
    if (self.numberTF == textField) {
        [textField resignFirstResponder];
    }
    
    return YES;
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
